package edu.java.texbooks.scjp.threads.test14;


public class Calculator extends Thread {

	// --- Instance Variables --------------------------------------------------
	private int total = 0;
	private static final int NUMBER = 10;

	// --- Constructors --------------------------------------------------------
	public Calculator(String name) {
		super(name);
		total = 0;
	}

	// --- Getters and Setters -------------------------------------------------
	public int getTotal() {
		return total;
	}

	// --- Methods -------------------------------------------------------------
	@Override
	public void run() {
		System.out.println(this.getName() + " goes to sleep...");
		try {
			Thread.sleep(25);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		synchronized (this) {
			System.out.println(this.getName()
					+ " Execute run() method of calculator.");
			for (int i = 0; i < NUMBER; i++) {
				System.out.println(total++);
			}
			// this.notify();
			// notifyAll();

		}

	}

	public synchronized void setTotal(int total) {
		this.total = total;
	}
}
